package com.test.sdk.core.controller;

import com.test.sdk.common.exception.SdkException;
import com.test.sdk.common.pojo.CP;
import com.test.sdk.common.pojo.Game;
import com.test.sdk.common.util.*;
import com.test.sdk.core.cache.CPCache;
import com.test.sdk.core.cache.GameCache;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 徒有琴
 */
@RestController
public class SystemController {

    @RequestMapping("init.html")
    public ResponseTO init(int cpId, int seqNum) throws SdkException {

        ResponseTO result = new ResponseTO();
        Game game = GameCache.getGameByCpIdAndSeqNum(cpId, seqNum);
        if (game == null) {
            throw new SdkException(ErrorConstants.GAME_NOT_EXIST);
        } else {
            Map<String, Object> map = new HashMap<>();
            map.put("repaireStatus", game.getRepairStatus());
            map.put("repaireContent", game.getRepairContent());
            map.put("version", game.getVersion());
            result.setResult(map);
        }
        return result;

    }

}
